#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
inline int read(){
    int res=0,f=1; char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        res=(res<<3)+(res<<1)+(ch^'0');
        ch=getchar();
    }
    return res*f;
}
int T,n,m,L,V;
int p[N+5],d[N+5],v[N+5],a[N+5],f=0,ans=0;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    T=read();
    while(T){
        --T;
        n=read();m=read();L=read();V=read();
        for(int i=1;i<=n;++i){
            d[i]=int(read());v[i]=int(read());a[i]=int(read());
            if(a[i]!=0) f=1;
        }
        for(int i=1;i<=m;++i) p[i]=int(read());
        for(int i=1;i<=n;++i){
            if(d[i]<=p[m]) ++ans;
        }
        if(!f) printf("%d 1\n",ans);
    }
    return 0;
}